<?php 
## include required files
/*******************************/
require_once '../model/users.php';
require_once '../model/moduleuser.php';
## Paginaton class
require_once ("../includes/classes/pagination_class.php");
/*******************************/
## Create Objects
/*******************************/
$userObj = new Model_Users();
$moduleObj=new Model_ModuleUser();
/*******************************/


/*******************************/
##Fetch all admin users from database
/******************************/

$userid= base64_decode($_GET['userid']);
$jobsID = base64_decode($_GET['id']);



##  --------- Pagination part first start --------------##
	if( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] != "" ) {
		$pageNum = $_GET[ 'page' ];
	} else {
		$pageNum = 1;
	} 
	$rowsPerPage = ROW_PER_PAGE;
	
	

	$pageName ="home.php?q=postjobs&userid=".$_GET['userid']."";

	## Count all the records
	$jobArray = $userObj->MYJOBLEADSAccordingToJOBId($jobsID,'','',false);
	$total_rows = count($jobArray);
	$offset	= ($pageNum - 1) * $rowsPerPage;
	$smarty->assign('page', $pageNum);
##  --------- Pagination part first end --------------##


##  --------- Pagination part second start --------------##
	$newid = $pageNum * $rowsPerPage - $rowsPerPage + 1;
	$smarty->assign('newid', $newid);
	$jobArray = $userObj->MYJOBLEADSAccordingToJOBId($jobsID,$rowsPerPage,$offset,true);
	//echo "<pre>"; print_r($jobArray);exit;
	
	for($k=0;$k<count($jobArray);$k++)
	{
		$userrating =$userObj->getUserRatingCount($jobArray[$k]['userid']);
		if($userrating)
		{
			$user_ratingcnt = @round($userrating['ratingsum']/$userrating['cnt']);		
		
			$total_rating = $user_ratingcnt;
			$jobArray[$k]['total_rating'] =$total_rating;
			//$smarty->assign('total_rating', $total_rating);
			if($total_rating < 5){
				$remaining_rating = 5 - $total_rating;
				$jobArray[$k]['remaining_rating'] =$remaining_rating;
				//$smarty->assign('remaining_rating', $remaining_rating);
			} 
		}
		else
		{
			$jobArray[$k]['total_rating'] =0;	
			$jobArray[$k]['remaining_rating'] =5;
		}
	}	
	
	$smarty->assign('jobsArray', $jobArray);
	

	$other_id = '';
	
	if($total_rows > ROW_PER_PAGE) {
		$pg = new pagination();					// CREATING OBJECT OF THE PAGINATION CLASS
		$pgnation = $pg->pagination_admin( $total_rows , $rowsPerPage , $pageNum , $pageName , $other_id, $class);	
		$smarty-> assign("pagination",$pgnation);
	}
##  --------- Pagination part second end --------------##	

## Fetch user details by id
if($_GET['userid'] != '') {
	$user_id = base64_decode($_GET['userid']);	
	$user_details = $userObj->getUserDetailsByUserId($user_id);
	$smarty->assign('user_details', $user_details);
}


## Assign session message to smarty variable and unset session variable
if($_SESSION['msg'] != '') {
	$smarty->assign('msg', $_SESSION['msg']);	
	unset($_SESSION['msg']);
}

## Set active class variable for left menu  (main menu and sub menu)
$smarty->assign('activeclass', 'postjobs');
$smarty->assign('mainmenu', '3');

## Unset all the objects created which are on this page
unset($userObj);
unset($moduleObj);

$smarty->display(TEMPLATEDIR_ADMIN. 'postjobs/jobleadinfo.tpl');
unset($smarty);
?>